# -*- coding: utf-8 -*- 
# 作者:飞虎
# 开发时间:2022/4/30 20:59
import sys
from PyQt5.Qt import *

app = QApplication(sys.argv)
window = QWidget()
window.resize(500, 500)
window.move(300, 300)

# 总控件的个数
widget_count = 100
# 一行有多少列
column_count = 3

# 计算一个控件的宽度
widget_width = int(window.width() / column_count)
# 总共有多少行(编号//列数+1)
row_count = (widget_count - 1) // column_count + 1
widget_height = int(window.height() / row_count)

for i in range(0, widget_count):
	w = QWidget(window)
	w.resize(widget_width, widget_height)
	widget_x = int((i % column_count) * widget_width)
	widget_y = int(i // column_count * widget_height)
	w.move(widget_x, widget_y)
	w.setStyleSheet('background-color:red;border:1px solid yellow;')

window.show()
app.exit(app.exec_())
